import logging
import os

from flask import Flask, send_from_directory

from webserver.account import account_bp
from webserver.task import task_bp
from webserver.task_board import taskboard_bp

app = Flask(__name__)

# 禁用 werkzeug 日志
log = logging.getLogger('werkzeug')
log.disabled = True


@app.route('/')
def index():
    return '<h1>Pixel Dashboard</h1> <a href="/snapshot.html">View Snapshot</a>'


@app.route('/<path:filename>')
def serve_static(filename):
    data_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), '../data'))
    return send_from_directory(data_directory, filename)


# 注册 task 蓝图
app.register_blueprint(task_bp, url_prefix='/api')
app.register_blueprint(taskboard_bp, url_prefix='/api')
app.register_blueprint(account_bp, url_prefix='/api')

if __name__ == "__main__":
    log.disabled = False
    app.run(port=10087)
